//---------------------------------------------------------------------------
#pragma hdrstop
#include "MatrClass.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
CMatr::CMatr() {
	cc = rc = 0;
}
//---------------------------------------------------------------------------
CMatr::~CMatr() {
	m.clear();
}
//---------------------------------------------------------------------------
void CMatr::addRow() {
	row tmp;
	for (int i = 0; i < cc; i++)
		tmp.push_back(0);
	m.push_back(tmp);
	rc++;
}
//---------------------------------------------------------------------------
void CMatr::addCol() {
	for (int i = 0; i < rc; i++)
		m[i].push_back(0);
	cc++;
}
//---------------------------------------------------------------------------
void CMatr::delRow(int index) {
	for (int i = index; i < rc - 1; i++)
		for (int j = 0; j < cc; j++)
			m[i][j] = m[i + 1][j];
	m.pop_back();
	rc--;
}
//---------------------------------------------------------------------------
void CMatr::delCol(int index) {
	for (int j = index; j < cc - 1; j++)
		for (int i = 0; i < rc; i++)
			m[i][j] = m[i][j + 1];
	for (int i = 0; i < rc; i++)
		m[i].pop_back();
	cc--;
}
//---------------------------------------------------------------------------
void CMatr::inc(int i, int j) {
	if (i <= rc && j <= cc)
		m[i][j]++;
}
//---------------------------------------------------------------------------
void CMatr::dec(int i, int j) {
	if (i <= rc && j <= cc) {
		m[i][j]--;
		if (m[i][j] < 0)
			m[i][j] = 0;
	}
}
//---------------------------------------------------------------------------
int CMatr::get(int i, int j) {
	if (i <= rc && j <= cc)
		return m[i][j];
	else
		return -1;
}
//---------------------------------------------------------------------------
void CMatr::null(int i, int j) {
	if (i <= rc && j <= cc)
		m[i][j] = 0;
}
//---------------------------------------------------------------------------
void CMatr::Out(TStringGrid *s) {
	for (int i = 1; i < s->RowCount; i++)
		for (int j = 1; j < s->ColCount; j++)
			s->Cells[j][i] = "";
	for (int i = 1; i <= rc; i++)
		for (int j = 1; j <= cc; j++)
			s->Cells[j][i] = m[i - 1][j - 1];
}
//---------------------------------------------------------------------------
